package cn.diancan.model.types;
import java.util.HashMap;
import java.util.Map;

/**
 * TransactionInfo 的交易状态
 * @author Sky
 *
 */
public enum TranStatusType {
     
    
    //-10 交易超时  -20交易失败  -30用户取消 -40系统关闭(用户不能再操作) -50 已退款  -60原路退款
    //10 ,"待付款" 20 ,"已付款" 30 ,"正在处理" 40,"待卖家发货" 46,"待买家确定收货" 200,"交易成功"
    
    /**待付款*/		PENDINGPAY	(10 ,"待付款"),
    /**已付款*/		PAYED		(20 ,"已付款"),
    /*提现拓展*/
    /**正在处理*/		HANDLEING	(30 ,"正在处理"),
    /*订单拓展*/
    /**待卖家发货*/		NOTSEND		(40,"待卖家发货"),
    /**待买家确定收货*/	SEND		(46,"待买家确定收货"),
    
    /**交易成功*/		SUCCESS		(200,"交易成功"),
    
    /**交易超时*/		TIMEOUT		(-10,"交易超时"),
    /**交易失败*/		FAIL		(-20,"交易失败"),
    /**用户取消*/		USERCANCEL	(-30,"用户取消"),
    /**系统关闭*/		SYSCLOSE	(-40,"系统关闭"),
    
    /**有退款*/		RETURNED	(-50,"退款"),
    //用外部接口
    /**退款中*/		RETURNING	(-57,"退款中"),
    /**原路退款*/		SRCRETURNED	(-60,"原路退款");
    
    
    // 成员变量
    private Integer statusType;
    private String statusDesc;
    
    
    public static String getTranStatus(Integer code){
	for (TranStatusType c : TranStatusType.values()) {
            if (c.getStatusType().equals(code)) {
                return c.getStatusDesc();
            }
        }
        return "";//不显示就好了
    }
    //获取所有(isFailStatus=0获取成功类型isFailStatus=1获取失败类型)
    public static  Map<String,String> getAll(Integer isFailStatus) {	
    	Map<String,String> map=new HashMap<String,String>(); 
    	if(null==isFailStatus){ 
		for (TranStatusType c : TranStatusType.values()) { 
	           map.put(c.getStatusType().toString(), c.getStatusDesc());
	        }
	}else if(isFailStatus.equals(0)){
    		for (TranStatusType c : TranStatusType.values()) {
    			if(c.getStatusType()>=0)
    	           map.put(c.getStatusType().toString(), c.getStatusDesc());
    	        }
    	}else if(isFailStatus.equals(1)){
    		for (TranStatusType c : TranStatusType.values()) {
    			if(c.getStatusType()<0)
    	           map.put(c.getStatusType().toString(), c.getStatusDesc());
    	        }
    	} 
    	return map;	
    }
    
    private TranStatusType( Integer statusType,String statusDesc) {
	this.statusDesc = statusDesc;
	this.statusType = statusType;
    }
    
    /**
     * 检查值是否存在
     * @param type
     * @return
     */
    public static boolean checkExists(Integer type){
	if(null==type){
	    return false;
	}
	TranStatusType enums[] =TranStatusType.values();
	for (int i = 0; i < enums.length; i++) {
	    TranStatusType singleEnum=  enums[i];
	    if(singleEnum.getStatusType().equals(type)){
		return true;
	    }
	}
	return false;
    }

    public String getStatusDesc() {
        return statusDesc;
    }

    public void setStatusDesc(String statusDesc) {
        this.statusDesc = statusDesc;
    }

    public Integer getStatusType() {
        return statusType;
    }

    public void setStatusType(Integer statusType) {
        this.statusType = statusType;
    } 
 

   
}
